public class SingleNumberFinder {

    // 找出只出现一次的元素
    public static int singleNumber(int[] nums) {
        int result = 0;
        for (int num : nums) {
            result ^= num;
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {4, 1, 2, 1, 2};
        int singleNumber = singleNumber(nums);
        System.out.println("只出现一次的元素是: " + singleNumber);
    }
}

